package tests;

import java.util.ArrayList;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import sources.Player;
import sources.ResultEnum;
import sources.RockPaperScissors;
import sources.RockPaperScissorsEnum;

public class RockPaperScissorsTest {

	private RockPaperScissors rockPaperScissors;

	@DataProvider
	public Object[][] win()
	{
		return new Object [][]{
				{RockPaperScissorsEnum.ROCK,RockPaperScissorsEnum.SCISSORS}
		};

	}
	@DataProvider
	public Object[][] tie()
	{
		return new Object [][]{
				{RockPaperScissorsEnum.ROCK,RockPaperScissorsEnum.ROCK}
		};

	}
	@DataProvider
	public Object[][] lose()
	{
		return new Object [][]{
				{RockPaperScissorsEnum.PAPER,RockPaperScissorsEnum.SCISSORS}
		};

	}

	@DataProvider
	public Object[][] player1win()
	{	
		List<RockPaperScissorsEnum> listplayer1 = new ArrayList<RockPaperScissorsEnum>();
		List<RockPaperScissorsEnum> listplayer2 =new ArrayList<RockPaperScissorsEnum>();
		for(int i=0;i<10;i++)
		{
			listplayer1.add(RockPaperScissorsEnum.PAPER);
			listplayer2.add(RockPaperScissorsEnum.ROCK);
		}
		return new Object [][]{
				{
					new Player(listplayer1, 0), new Player(listplayer2, 0)
				}
		};
	}
	@DataProvider
	public Object[][] player1tie()
	{
		List<RockPaperScissorsEnum> listPlayer1 = new ArrayList<RockPaperScissorsEnum>();
		List<RockPaperScissorsEnum> listPlayer2 =new ArrayList<RockPaperScissorsEnum>();
		for(int i=0;i<10;i++)
		{
			listPlayer1.add(RockPaperScissorsEnum.PAPER);
			listPlayer2.add(RockPaperScissorsEnum.PAPER);
		}
		return new Object [][]{
				{
					new Player(listPlayer1, 0), new Player(listPlayer2, 0)
				}
		};
	}
	@DataProvider
	public Object[][] player1lose()
	{
		List<RockPaperScissorsEnum> listplayer1 = new ArrayList<RockPaperScissorsEnum>();
		List<RockPaperScissorsEnum> listplayer2 =new ArrayList<RockPaperScissorsEnum>();
		for(int i=0;i<10;i++)
		{
			listplayer1.add(RockPaperScissorsEnum.ROCK);
			listplayer2.add(RockPaperScissorsEnum.PAPER);
		}
		return new Object [][]{
				{
					new Player(listplayer1, 0), new Player(listplayer2, 0)
				}
		};
	}

	@Test(dataProvider="win")
	void testWinPlay(RockPaperScissorsEnum player1, RockPaperScissorsEnum player2) {

		Assert.assertEquals(rockPaperScissors.play(RockPaperScissorsEnum.valueOf(player1.toString()), RockPaperScissorsEnum.valueOf(player2.toString())),ResultEnum.WIN);

	}
	@Test(dataProvider="tie")
	void testTiePlay(RockPaperScissorsEnum player1, RockPaperScissorsEnum player2) {
		Assert.assertEquals(rockPaperScissors.play(RockPaperScissorsEnum.valueOf(player1.toString()), RockPaperScissorsEnum.valueOf(player2.toString())),ResultEnum.TIE);

	}
	@Test(dataProvider="lose")
	void testlosePlay(RockPaperScissorsEnum player1, RockPaperScissorsEnum player2) {
		Assert.assertEquals(rockPaperScissors.play(RockPaperScissorsEnum.valueOf(player1.toString()), RockPaperScissorsEnum.valueOf(player2.toString())),ResultEnum.LOSE);

	}

	@Test(dataProvider="player1win")
	void testWinPlayList(Player player1, Player player2) {
		Assert.assertEquals(rockPaperScissors.play(player1, player2),ResultEnum.WIN);
	}

	@Test(dataProvider="player1tie")
	void testTiePlayList(Player player1, Player player2) {
		Assert.assertEquals(rockPaperScissors.play(player1, player2),ResultEnum.TIE);
	}
	@Test(dataProvider="player1lose")
	void testLosePlayList(Player player1, Player player2) {
		Assert.assertEquals(rockPaperScissors.play(player1, player2),ResultEnum.LOSE);
	}

	@BeforeClass
	void setUpClass() {
		rockPaperScissors = new RockPaperScissors();
	}

	@AfterClass
	public void afterClass() {
		rockPaperScissors = null;
	}

}
